<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Glcompany_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }
    public function insert_company($data){
        $this->db->query("call gl_company_ins(?,?,?,?,?,?,?,?,?,?,@id,@err,@msg)",$data);
        $que = $this->db->query("SELECT @id as id , @err as error , @msg as msg");
        echo json_encode($que->result());
    }
    public function update_company($data){
        $this->db->query("call gl_company_upd(?,?,?,?,?,?,?,?,?,?,@err,@msg)",$data);
        $que = $this->db->query("SELECT @err as error , @msg as msg");
        echo json_encode($que->result());
    }
    public function search_company($name){
      $sql   = "SELECT * FROM gl_company WHERE company_name LIKE ".$this->db->escape($name)." ";
      $query = $this->db->query($sql);
          if($query->num_rows() != 0){
            return $query->result();
          }
          else {
            $result = "No results found.";
            return $result;
          }
    }

    public function get_company_data($id){
      $this->db->where('company_id', $id);
      $query = $this->db->get('gl_company');
      return $query->result();
    }
    public function get_bu(){
      $sql = "SELECT * FROM gl_business_units";
      $query = $this->db->query($sql);
      return $query->result();
    } 
}